import { BinarySearch } from "../../api/math/BinarySearch";
import { CDUnitLv } from "../excel/CDUnitLv";


/**
 * 扩展-主角升级
 */
export abstract class CEUnitLv {
    /**每级累积经验（升级到这个等级满需要用多少） */
    public static lvExpCount: number[] = [];

    /**
     * 初始化
     */
    public static init(): void {
        const list = this.lvExpCount;
        const vs = CDUnitLv.datas.getValues();
        const len = vs.length;
        list[0] = 0;
        for (let i = 0; i < len; i++) {
            list[i + 1] = list[i] + vs[i].exp;
        }
        //最后一级配了-1，要返回来
        list[len]++;
    }


    /**
    * 获取经验对应的等级
    * @param exp 
    */
    public static getExpLevel(exp: number): number {
        const idx = BinarySearch.getInsertIndex(this.lvExpCount, exp);
        if (BinarySearch.findEqualWhenInsert) {
            return idx + 1;
        }
        else {
            return idx;
        }
    }
    /**
     * 获取最大等级
     */
    public static getMaxLevel(): number {
        return this.lvExpCount.length - 1;
    }
}